#include "pch.h"

int write_str(const std::string &s1, std::ofstream &ofs)
{
    int len = s1.size();
    ofs.write((const char *)&len, sizeof(len));
    ofs.write(s1.c_str(), s1.size());

    return len;
};

int read_str(std::string &s1, std::ifstream &ifs)
{

    int len2;
    ifs.read((char *)&len2, sizeof(len2));
    s1.resize(len2);
    ifs.read(&s1[0], len2);

    return len2;
}

int main()
{

    std::string name = "objectName";
    std::ofstream ofs("hel");
    write_str(name, ofs);

    ofs.flush();
    ofs.close();

    std::string n2;
    std::ifstream ifs("hel");
    read_str(n2, ifs);
    LOGI("n2 is %s", n2.c_str());
    ifs.close();
};